
*For Margaret dropbox folders 
global NCREIF "/Users/BeckaBrolinson/Dropbox/NCREIF/data" 
global build 	"$NCREIF/build" 
global analysis "$NCREIF/analysis"
global results 	"$analysis/results"
global figures 	"$analysis/figures" 


*ssc install erepost
*------------------------------------------------------------------------------*
*	Step 3- Unmatched FE Diff In Diff 	   *
*------------------------------------------------------------------------------*

	use "$build/01_annualizeddatawcontrol.dta", replace

	gen sqft1000s = sqft / 1000 
	gen HDD1000s = HDD / 1000 
	gen CDD1000s = CDD / 1000 
	gen used_space1000s = used_space/ 1000
	gen real_capex_ti_sqft = real_capex_ti / sqft 
	gen real_capex_bldimp_sqft = real_capex_bldimp / sqft 
	gen years_pre_post_cert= year-firstyearrated
	
	gen post_1 = (years_pre_post_cert>=-1) 
	
	gen interaction_1 = post_1 * treat 

	
	set more off 
	*List of covariates 
	#d ;
	global Cov0 	""; 
	global Cov1 	"Covered_E real_elecprice real_gasprice Unemployment HDD1000s CDD1000s 
	age age2 used_space1000s
	 percentleased real_capex_ti_sqft real_capex_bldimp_sqft "; 
	global Cov2 	"Covered_E real_elecprice real_gasprice Unemployment HDD1000s CDD1000s
	 age age2 percentleased used_space1000s
	dFundType1 dFundType2 dFundType4 dFundType5 dFundType6";
	global Cov3	"Covered_E real_elecprice Unemployment HDD1000s CDD1000s 
	age age2 used_space1000s"; 
	#d cr 

	label var interaction "Cert*Post" 
	label var interaction_1 "Cert*Post (Including Year Prior to Cert.)"
	label var treat "1[treat=1]"
	label var logrealrentpersf "ln(Rent/Sq. Ft.) (\\$)"
	label var Covered_E "Benchmarking Law" 
	label var real_elecprice "Avg. Elec. Price (\\$/MWh)" 
	label var real_gasprice "Avg. Gas Price (\\$/Mcf)" 
	label var Unemployment "Unemployment" 
	label var age "Building Age" 
	label var age2 "Building Age Squared" 
	label var used_space "Used Space (Pct. Leased * Sq. Ft.)"
	label var used_space1000s "Used Space (Pct. Leased * Sq. Ft.) (1000s)"
	labe var percentleased "Percent Leased (\%)"
	label var real_capex_ti "Cap Exp. (Tenant Imp.)" 
	label var real_capex_ti_sqft "Cap Exp./Sq. Ft. (Tenant Imp.) (\\$)"
	label var real_capex_bldimp "Cap Exp. (Bldg. Imp.)"
	label var real_capex_bldimp_sqft "Cap Exp./Sq. Ft. (Bldg. Imp.) (\\$)"
	label var HDD "HDD" 
	label var HDD1000s "HDD (1000s)" 
	label var CDD "CDD" 
	label var CDD1000s "CDD (1000s)" 
	label var rl_yr_rentpersf "Rent per Sq. Ft."
	label var logrealutilpersf "ln(Util/Sq. Ft.) (\\$)"
	label var rl_yr_rentpersf "Rent per Sq. Ft."
	label var rl_yr_utilpersf "Util. per Sq. Ft."
	label var yrbuilt "Year Built" 
	label var sqft "Square Feet"
	label var sqft1000s "Square Feet (1000s)" 
	
	
	
*Run the FE regression of real rent per sqft on treat*post 
	local Covariates "Cov0 Cov1 Cov2 Cov3" 
	foreach Cov of local Covariates{
	eststo RentFE1: reghdfe logrealrentpersf interaction treat, absorb(i.city_cat#i.year) vce(cluster cbsa)
	estfe  RentFE1, labels(year "Year FE" city_cat#year "City by Year FE")
	eststo RentCov1_FE: reghdfe logrealrentpersf interaction treat $Cov1, absorb(i.city_cat#i.year) vce(cluster cbsa)
	estfe  RentCov1_FE, labels(year "Year FE" city_cat#year "City by Year FE")
	eststo RentFE`Cov': reghdfe logrealrentpersf interaction $`Cov', absorb(i.propnum i.city_cat#i.year) vce(cluster cbsa)
	estfe  RentFE`Cov', labels(year "Year FE" city_cat#year "City by Year FE" propnum "Property FE")
	}
	
	
	*make Latex Table 
	esttab RentFE1 RentCov1_FE RentFECov1 RentFECov3 using "$results/01_rentpersf_unmatched.tex" , label replace booktabs ///
	alignment(SSSS) ///
	b(%12.3f) se(%12.3f) star(* 0.05) /// sets format of parameters, standard errors, and stars
	stats(N, fmt(%9.0fc)) /// adds comma to Observation number
	nonotes nogaps /// removes notes from bottom of table 
	indicate(`r(indicate_fe)', label("Y" "")) /// adds y & N for FE inclusions
	title(Unmatched Sample: Energy Star Certification and Rent Per Sq. Ft. \label{tab01rentpersfunmatched}) ///
	addnote({\scriptsize * p$<$0.05. The standard errors reported in parenthesis have been clustered at the CBSA level.})

*Run the FE regression of real rent per sqft on treat*post 
	local Covariates "Cov0 Cov1 Cov2 Cov3" 
	foreach Cov of local Covariates{
	eststo RentFE1_1: reghdfe logrealrentpersf interaction_1 treat, absorb(i.city_cat#i.year) vce(cluster cbsa)
	estfe  RentFE1_1, labels(year "Year FE" city_cat#year "City by Year FE")
	eststo RentCov1_FE_1: reghdfe logrealrentpersf interaction_1 treat $Cov1, absorb(i.city_cat#i.year) vce(cluster cbsa)
	estfe  RentCov1_FE_1, labels(year "Year FE" city_cat#year "City by Year FE")
	eststo RentFE`Cov'_1: reghdfe logrealrentpersf interaction_1 $`Cov', absorb(i.propnum i.city_cat#i.year) vce(cluster cbsa)
	estfe  RentFE`Cov'_1, labels(year "Year FE" city_cat#year "City by Year FE" propnum "Property FE")
	}
	
	
	*make Latex Table 
	esttab RentFE1_1 RentCov1_FE_1 RentFECov1_1 RentFECov3_1 using "$results/01_01_rentpersf_unmatched.tex" , label replace booktabs ///
	alignment(SSSS) ///
	b(%12.3f) se(%12.3f) star(* 0.05) /// sets format of parameters, standard errors, and stars
	stats(N, fmt(%9.0fc)) /// adds comma to Observation number
	nonotes nogaps /// removes notes from bottom of table 
	indicate(`r(indicate_fe)', label("Y" "")) /// adds y & N for FE inclusions
	title(Unmatched Sample: Energy Star Certification and Rent Per Sq. Ft. \label{appendixtab0101rentpersfunmatched}) ///
	addnote({\scriptsize * p$<$0.05. The standard errors reported in parenthesis have been clustered at the CBSA level.})


		
*using hdfe
	local Covariates "Cov0 Cov1 Cov2 Cov3" 
	foreach Cov of local Covariates{
	eststo UtilFE1: reghdfe logrealutilpersf interaction treat, absorb(i.city_cat#i.year) vce(cluster cbsa)
	estfe  UtilFE1, labels(year "Year FE" city_cat#year "City by Year FE")
	eststo UtilFECov1_FE: reghdfe logrealutilpersf interaction rl_yr_rentpersf treat $Cov1 , absorb(i.city_cat#i.year) vce(cluster cbsa)
	estfe UtilFECov1_FE, labels(year "Year FE" city_cat#year "City by Year FE")
	eststo UtilFE`Cov': reghdfe logrealutilpersf interaction rl_yr_rentpersf $`Cov' , absorb(i.propnum i.city_cat#i.year) vce(cluster cbsa)
	estfe  UtilFE`Cov', labels(year "Year FE" city_cat#year "City by Year FE" propnum "Property FE")
	}
	
	*Make Latex table 
	esttab UtilFE1 UtilFECov1_FE UtilFECov1 UtilFECov3 using "$results/02_utilpersf_unmatched.tex" , label replace booktabs ///
	b(%12.3f) se(%12.3f) star(* 0.05) /// sets format of parameters, standard errors, and stars
	stats(N, fmt(%9.0fc)) /// adds comma to Observation number
	nonotes nogaps /// removes notes from bottom of table and removes vertical gaps
	indicate(`r(indicate_fe)', label("Y" "")) /// adds y & N for FE inclusions
	title(Unmatched Sample: Energy Star Certification and Utility Expenditure Per Sq. Ft. \label{tab02utilpersfunmatched}) ///
	alignment(SSSS) ///
	addnote({\scriptsize * p$<$0.05. The standard errors reported in parenthesis have been clustered at the CBSA level.})

			
*using hdfe 
	local Covariates "Cov0 Cov1 Cov2 Cov3" 
	foreach Cov of local Covariates{
	eststo UtilFE1_1: reghdfe logrealutilpersf interaction_1 treat, absorb(i.city_cat#i.year) vce(cluster cbsa)
	estfe  UtilFE1_1, labels(year "Year FE" city_cat#year "City by Year FE")
	eststo UtilFECov1_FE_1: reghdfe logrealutilpersf interaction_1 rl_yr_rentpersf treat $Cov1 , absorb(i.city_cat#i.year) vce(cluster cbsa)
	estfe UtilFECov1_FE_1, labels(year "Year FE" city_cat#year "City by Year FE")
	eststo UtilFE`Cov'_1: reghdfe logrealutilpersf interaction_1 rl_yr_rentpersf $`Cov' , absorb(i.propnum i.city_cat#i.year) vce(cluster cbsa)
	estfe  UtilFE`Cov'_1, labels(year "Year FE" city_cat#year "City by Year FE" propnum "Property FE")
	}
	
	*Make Latex table 
	esttab UtilFE1_1 UtilFECov1_FE_1 UtilFECov1_1 UtilFECov3_1 using "$results/02_01_utilpersf_unmatched.tex" , label replace booktabs ///
	b(%12.3f) se(%12.3f) star(* 0.05) /// sets format of parameters, standard errors, and stars
	stats(N, fmt(%9.0fc)) /// adds comma to Observation number
	nonotes nogaps /// removes notes from bottom of table and removes vertical gaps
	indicate(`r(indicate_fe)', label("Y" "")) /// adds y & N for FE inclusions
	title(Unmatched Sample: Energy Star Certification and Utility Expenditure Per Sq. Ft. \label{appendixtab0201utilpersfunmatched}) ///
	alignment(SSSS) ///
	addnote({\scriptsize * p$<$0.05. The standard errors reported in parenthesis have been clustered at the CBSA level.})
